import Mock from 'mockjs'
// const Mock = require('mockjs')
// 通用数据模板
const baseTemplate = {
  'id|+1': 1,
  timestamp: Mock.Random.now(),
  'status|1': ['success', 'error']
}
// 用户信息
export const generateData1 = ({id,name}) => ({
  data: Mock.mock({
    ...baseTemplate,
    name: Mock.Random.cname(),
    'age|18-60': 1,
    email: Mock.Random.email()
  }),
  code: 200,
  msg: ''
})
// 公司信息
export const generateData2 = ({id,company}) => ({
  data: Mock.mock({
    ...baseTemplate,
    company: Mock.Random.cword(3, 5) + '公司', // 使用cword生成公司名称
    address: Mock.Random.county(true),
    'score|1-100.2': 1
  }),
  code: 200,
  msg: ''
})
// 营业额
export const generateData3 = ({id}) => ({
  data: Mock.mock({
    ...baseTemplate,
    product: Mock.Random.ctitle(),
    'price|100-5000': 1,
    'stock|0-1000': 1
  }),
  code: 200,
  msg: ''
})
// 订单信息
export const generateData4 = ({id,orderId}) => ({
  data: Mock.mock({
    ...baseTemplate,
    orderId: Mock.Random.guid(),
    payment: Mock.Random.float(100, 9999, 2, 2),
    createTime: Mock.Random.datetime()
  }),
  code: 200,
  msg: ''
})
// 图片信息
export const generateData5 = ({id}) => ({
  data: Mock.mock({
    ...baseTemplate,
    image: Mock.Random.image('200x100'),
    color: Mock.Random.color(),
    'tags|3': [Mock.Random.word(3, 5)]
  }),
  code: 200,
  msg: ''
})
// 位置信息
export const generateData6 = ({id,page}) => ({
  data: Mock.mock({
    ...baseTemplate,
    coordinates: {
      latitude: Mock.Random.float(-90, 90, 6, 6),
      longitude: Mock.Random.float(-180, 180, 6, 6)
    },
    'value|0-1.2': 1,
    description: Mock.Random.csentence()
  }),
  code: 200,
  msg: ''
})
// 数据信息
export const generateData7 = ({id:page}) => ({
  data: Mock.mock({
    ...baseTemplate,
    nestedData: {
      'list|5': [{
        'key|+1': 1,
        'value': Mock.Random.float()
      }]
    }
  }),
  code: 200,
  msg: ''
})
// 统计信息
export const generateData8 = ({id,name}) => ({
  data: Mock.mock({
    ...baseTemplate,
    'array|5-10': [{
      'name': Mock.Random.cword(3, 5),
      'count|1-100': 1
    }]
  }),
  code: 200,
  msg: ''
})
// 选项信息
export const generateData9 = ({id,rate,page}) => ({
  data: Mock.mock({
    ...baseTemplate,
    'rate|1-5': 1,
    'isValid|1': true,
    'options|3': Mock.Random.word(4, 8)
  }),
  code: 200,
  msg: ''
})
// 其他信息
export const generateData10 = ({id,number,page}) => ({
  data: Mock.mock({
    ...baseTemplate,
    'string|1-10': '★',
    'number|1-100': 100,
    'boolean|1': true,
    'probability|0-1.2': 1,
    'hex': Mock.Random.hex(),
    // 使用原生正则表达式替代 Mock.Random.regex
    'regex': () => {
      const letters = 'abcdefghijklmnopqrstuvwxyz';
      const numbers = '0123456789';
      const randomLetters = Array.from({length: 3}, () => letters[Math.floor(Math.random() * letters.length)]).join('');
      const randomNumbers = Array.from({length: 2}, () => numbers[Math.floor(Math.random() * numbers.length)]).join('');
      return randomLetters + randomNumbers;
    }
  }),
  code: 200,
  msg: ''
})
